import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { NewBFEnterCellData } from "../cellData/NewBFEnterCellData";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
//class NewBFEnterCellRenderer
    
    export  class NewBFEnterCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._btnEnter = ObjCreate.createGLoadedButton(ResFileConst.PeaceFieldBtn, 5, 5, 105, 106, this);
            var loc1=new GImageBitmap("newbattleFieldTxt.png", 20, 60);
            this.addChild(loc1);
            var loc2=new GTextFormat(FontUtil.EmbedNumberName, 50, 16776960);
            loc2.align = flash.text.TextFormatAlign.CENTER;
            this._tfIndex = new Object /* flash.text.TextField */();
            this._tfIndex.embedFonts = true;
            this._tfIndex.defaultTextFormat = loc2;
            ObjCreate.setObjAttri(this._tfIndex, 0, 12, 105, 50, this);
            this._tfIndex.mouseEnabled = false;
            this._txtNum = ObjCreate.createTextField(Language.getStringByParam(41672, "0"), 27, 82, 100, 20, this, GlobalStyle.textFormat6);
            this._txtVIPNum = ObjCreate.createTextField("(VIP 0/100)", 22, 100, 100, 20, this, GlobalStyle.textFormatGreen);
            this._tfClose = ObjCreate.createTextField(Language.getString(41696), 33, 85, 100, 20, this, GlobalStyle.textFormatRed);
            this._tfClose.visible = false;
            this._btnEnter.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnEnterClick);
            return;
        }

        /* internal  */onBtnEnterClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NewBattlefieldRequestComein, this._cellData.info.fieldId));
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (typeof arg1 === "newbfentercelldata") 
            {
                this._cellData = arg1 as NewBFEnterCellData;
                this.updateView();
            }
            return;
        }

        /* internal  */updateView(): void
        {
            this._tfIndex.text = this._cellData.index.toString();
            this._btnEnter.enabled = this._cellData.isCanEnter;
            this._txtNum.text = Language.getStringByParam(41672, this._cellData.info.playerNum.toString());
            this._txtVIPNum.text = "(VIP " + this._cellData.info.playerNum + "/100)";
            this._txtNum.visible = !this._cellData.info.close;
            this._txtVIPNum.visible = !this._cellData.info.close;
            this._tfClose.visible = this._cellData.info.close;
            this._btnEnter.drawNow();
            return;
        }

        /* internal */ /* var */_btnEnter: GLoadedButton;

        /* internal */ /* var */_txtNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_txtVIPNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfIndex: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfClose: Object /* flash.text.TextField */;

        /* internal */ /* var */_cellData: NewBFEnterCellData;
    }
